package com.example.dockerdemo;

import org.junit.jupiter.api.Test;

import javax.swing.*;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import static com.sun.glass.ui.Cursor.setVisible;
import static com.sun.java.accessibility.util.AWTEventMonitor.addMouseListener;

/**
 * @PACKAGE_NAME: com.example.dockerdemo
 * @NAME: AutoMouse
 * @description:
 * @DATE: 2024/5/8
 * @USER: fz
 **/
public class AutoMouse {

    @Test
    public void test() {
        try {
            while (true) {
                Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
                int x = (int) mouseLocation.getX();
                int y = (int) mouseLocation.getY();

                System.out.println("Mouse X: " + x + ", Mouse Y: " + y);

                Thread.sleep(1000); // 每秒更新一次鼠标位置
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    @Test
    public void test2() {
        try {
            Robot robot = new Robot();
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); // 模拟鼠标左键按下

            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); // 模拟鼠标左键释放

            robot.delay(1000); // 等待1秒

            // 模拟鼠标左键点击
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

            // 监听鼠标左键点击事件
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); // 模拟鼠标左键按下
            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); // 模拟鼠标左键释放
            robot.delay(1000); // 等待1秒

            int x = java.awt.MouseInfo.getPointerInfo().getLocation().x;
            int y = java.awt.MouseInfo.getPointerInfo().getLocation().y;

            System.out.println("Mouse Left Clicked at X: " + x + ", Y: " + y);

        } catch (AWTException e) {
            e.printStackTrace();
        }
    }
    @Test
    public void test3() {
        try {
            Robot robot = new Robot();

            // 创建鼠标事件监听器
            MouseAdapter mouseAdapter = new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {

                    if (e.getButton() == MouseEvent.BUTTON1) {
                        int x = e.getXOnScreen();
                        int y = e.getYOnScreen();
                        System.out.println("Mouse Left Clicked at X: " + x + ", Y: " + y);
                    }
                }
            };

            // 添加鼠标监听器
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); // 模拟鼠标左键按下
            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); // 模拟鼠标左键释放
            robot.delay(1000); // 等待1秒

            // 移除鼠标监听器
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); // 模拟鼠标左键按下
            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); // 模拟鼠标左键释放


        } catch (AWTException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void test4() {
        try {

            Thread.sleep(1000);
            Robot robot = new Robot();
            robot.mouseMove(1776,18);
            Thread.sleep(1000);
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); // 模拟鼠标左键按下
            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); // 模拟鼠标左键释放
        } catch (AWTException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    @Test
    public void test5() {
        addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent e) {
                System.out.println("Mouse X Coordinate: " + e.getX());
                System.out.println("Mouse Y Coordinate: " + e.getY());
            }
        });


        setVisible(true);
    }


}


